package fussbudget.SQL;

import fussbudget.PaymentEntity;
import fussbudget.ScheduledTransaction;
import fussbudget.SimpleTransaction;
import fussbudget.Transaction;

public class FBSQL extends SQLUtility {

	public static int addPaymentEntity(PaymentEntity newPaymentEntity) {
		int id = -1;
		id = SQLUtility.addString("paymentEntity", "name", newPaymentEntity.getName());
		return id;
	}

	public static int addSimpleTransaction(SimpleTransaction simpleTransaction) {
		int id = -1;

		id = SQLUtility.addLong("simpleTransaction", "date", simpleTransaction.getDate().getMillis());
		SQLUtility.alterDecimal("simpleTransaction", "amount", simpleTransaction.getAmount(), id);
		return id;
	}

	public static int addTransaction(Transaction transaction) {
		int id = -1;

		id = SQLUtility.addString("transaction", "name", transaction.getName());
		SQLUtility.alterInt("transaction", "idDue", transaction.getDue().getId(), id);
		SQLUtility.alterInt("transaction", "idExpected", transaction.getExpected().getId(), id);
		SQLUtility.alterInt("transaction", "idActual", transaction.getActual().getId(), id);
		return id;
	}

	public static int addScheduledTransaction(ScheduledTransaction scheduledTransaction) {
		int id = -1;
		id = SQLUtility.addString("scheduledTransaction", "name", scheduledTransaction.getName());
		SQLUtility.alterInt("scheduledTransaction", "idStartTransaction", scheduledTransaction.getStartTransaction().getId(), id);
		SQLUtility.alterString("scheduledTransaction", "recurrance", scheduledTransaction.getRecurrance().name(), id);
		SQLUtility.alterInt("scheduledTransaction", "idPaymentEntity", scheduledTransaction.getPaymentEntity().getId(), id);
		switch(scheduledTransaction.getType()){
			case DEPOSIT:
				SQLUtility.alterBoolean("scheduledTransaction", "isDeposit", true, id);
				break;
			case PAYMENT:
				SQLUtility.alterBoolean("scheduledTransaction", "isDeposit", false, id);
				break;
		}
		
		return id;
	}

}
